package io.wdb.modules.generator.generator.service.impl.book;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;

import io.wdb.common.utils.PageHelperUtil;
import io.wdb.common.utils.Query;
import io.wdb.modules.generator.generator.dao.BookInfoDao;
import io.wdb.modules.generator.generator.entity.BookTopicalMappingsEntity;
import io.wdb.modules.generator.generator.entity.customer.BookInfoEntityCustomer;
import io.wdb.modules.generator.generator.service.BookBatchImportService;

@Service
public class BookBatchImportServiceImpl implements BookBatchImportService{

	@Autowired
	private BookInfoDao bookInfoDao;
	
	/*@Autowired
	private BookTopicalDao bookTopicalDao;
	
	@Autowired
	private BookTopicalMappingsDao bookTopicalMappingsDao;*/
	
	@Override
	public List<BookInfoEntityCustomer> list(Map<String, Object> params) {
		if(params.get("page")!=null) {
			Query query = new Query(params);
			PageHelper.startPage(PageHelperUtil.getPageNum(query), PageHelperUtil.getPageSize(query));
		}
		List<BookInfoEntityCustomer> bookInfoEntityCustomers = bookInfoDao.queryImport(params);
		/*for(BookInfoEntityCustomer bookInfoEntityCustomer:bookInfoEntityCustomers) {
			StringBuffer buffer = new StringBuffer();
			List<BookTopicalMappingsEntity> bookTopicalMappingsEntities = bookInfoEntityCustomer.getBookTopicalMappings();
			for(BookTopicalMappingsEntity bookTopicalMappingsEntity:bookTopicalMappingsEntities) {
				if(buffer.length()>0) {
					buffer.append(",");
				}
				buffer.append(bookTopicalMappingsEntity.getTopicalName());
			}
			bookInfoEntityCustomer.setBookTopical(buffer.toString());
		}*/
		
		/*for(BookInfoEntityCustomer bookInfoEntityCustomer:bookInfoEntityCustomers) {
			StringBuffer buffer = new StringBuffer();
			List<BookTopicEntityCustomer> bookTopicalEntities = bookTopicalDao.getBookTopicByIsbn(bookInfoEntityCustomer.getIsbnNo());
			for(BookTopicEntityCustomer bookTopicEntityCustomer:bookTopicalEntities) {
				if(buffer.length()>0) {
					buffer.append(",");
				}
				String topicalName = bookTopicalMappingsDao.getTopicalNameByCode(bookTopicEntityCustomer.getTopicalCode());
				buffer.append(topicalName);
			}
			bookInfoEntityCustomer.setCategory(buffer.toString());
		}*/
		return bookInfoEntityCustomers;
	}
}
